import 'package:flutter/material.dart';
import 'package:vibration/vibration.dart';

class VibratingApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('振动插件示例应用程序'),
        ),
        body: Builder(
          builder: (BuildContext context) {
            return Center(
              child: Column(
                children: <Widget>[
                  ElevatedButton(
                    child: Text('默认振动 200ms'),
                    onPressed: () {
                      Vibration.vibrate(
                          duration: 10,
                          amplitude:1,
                      );
                    },
                  ),
                  ElevatedButton(
                    child: Text('默认振动 500ms'),
                    onPressed: () {
                      Vibration.vibrate();
                    },
                  ),
                  ElevatedButton(
                    child: Text('震动1000ms'),
                    onPressed: () {
                      Vibration.vibrate(duration: 1000);
                    },
                  ),
                  ElevatedButton(
                    child: Text('随模式振动'),
                    onPressed: () {
                      final snackBar = SnackBar(
                        content: Text(
                          '模式：等待0.5秒，振动1秒，等待0.5秒，振动2秒，等待0.5秒，振动3秒，等待0.5秒，振动0.5秒',
                        ),
                      );
                      ScaffoldMessenger.of(context).showSnackBar(snackBar);
                      Vibration.vibrate(
                        pattern: [500, 1000, 500, 2000, 500, 3000, 500, 500],
                      );
                    },
                  ),
                  ElevatedButton(
                    child: Text('以模式和振幅振动'),
                    onPressed: () {
                      final snackBar = SnackBar(
                        content: Text(
                          '模式：等待0.5秒，振动1秒，等待0.5秒，振动2秒，等待0.5秒，振动3秒，等待0.5秒，振动0.5秒',
                        ),
                      );

                      ScaffoldMessenger.of(context).showSnackBar(snackBar);
                      Vibration.vibrate(
                        pattern: [500, 1000, 500, 2000, 500, 3000, 500, 500],
                        intensities: [0, 128, 0, 255, 0, 64, 0, 255],
                      );
                    },
                  )
                ],
              ),
            );
          },
        ),
      ),
    );
  }
}